package com.pyg.goods.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import com.pyg.pojo.TbPayLogExample;
import com.pyg.pojo.TbPayLogExample.Criteria;
import com.pyg.mapper.TbPayLogMapper;
import com.pyg.pojo.TbPayLog;
import com.pyg.goods.service.TbPayLogService;

import com.pyg.utils.PygStringUtils;
import entity.PageResult;

/**	*  @Author zhuliangcai
*  @Email zhuliangcai@itcast.cn
*  @Date 2018-04-03 20:07:45
*/
@Service
public class TbPayLogServiceImpl implements TbPayLogService {
	@Autowired
	private TbPayLogMapper tbPayLogMapper;

	@Override
	public List<TbPayLog> findAll() {
		return tbPayLogMapper.selectByExample(null);
	}

	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		// 开启分页插件功能
		PageHelper.startPage(pageNum, pageSize);

		Page<TbPayLog> page = (Page<TbPayLog>) tbPayLogMapper.selectByExample(null);

		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 品牌条件分页
	 *
	 * @param TbPayLog
	 *            查询条件
	 * @param pageNum
	 *            当前页面
	 * @param pageSize
	 *            每页记录数
	 * @return
	 */
	@Override
	public PageResult findPage(TbPayLog tbPayLog, int pageNum, int pageSize) {
		// 开启分页插件功能
		PageHelper.startPage(pageNum, pageSize);

		TbPayLogExample example = null;
		if (tbPayLog != null) {
			example = new TbPayLogExample();
			Criteria criteria = example.createCriteria();
			if (PygStringUtils.isNotEmpty(tbPayLog.getOutTradeNo())) {
				criteria.andOutTradeNoLike("%" + tbPayLog.getOutTradeNo() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbPayLog.getCreateTime())) {
				criteria.andCreateTimeEqualTo(tbPayLog.getCreateTime() );
			}
			if (PygStringUtils.isNotEmpty(tbPayLog.getPayTime())) {
				criteria.andPayTimeEqualTo(tbPayLog.getPayTime() );
			}
			if (PygStringUtils.isNotEmpty(tbPayLog.getTotalFee())) {
				criteria.andTotalFeeEqualTo(tbPayLog.getTotalFee() );
			}
			if (PygStringUtils.isNotEmpty(tbPayLog.getUserId())) {
				criteria.andUserIdLike("%" + tbPayLog.getUserId() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbPayLog.getTransactionId())) {
				criteria.andTransactionIdLike("%" + tbPayLog.getTransactionId() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbPayLog.getTradeState())) {
				criteria.andTradeStateLike("%" + tbPayLog.getTradeState() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbPayLog.getOrderList())) {
				criteria.andOrderListLike("%" + tbPayLog.getOrderList() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbPayLog.getPayType())) {
				criteria.andPayTypeLike("%" + tbPayLog.getPayType() + "%");
			}
		}

		Page<TbPayLog> page = (Page<TbPayLog>) tbPayLogMapper.selectByExample(example);

		return new PageResult(page.getTotal(), page.getResult());
	}

	@Override
	public void add(TbPayLog tbPayLog) {
		tbPayLogMapper.insert(tbPayLog);
	}

	@Override
	public void del(String[] ids) {
		for (String id : ids) {
			tbPayLogMapper.deleteByPrimaryKey(id);
		}
	}

	@Override
	public TbPayLog findOne(String id) {
		return tbPayLogMapper.selectByPrimaryKey(id);
	}

	@Override
	public void update(TbPayLog tbPayLog) {
		tbPayLogMapper.updateByPrimaryKey(tbPayLog);
	}

}
